<template>
	<view style="padding-bottom: 100upx;" class="address">	
		
		<uni-nav-bar fixed="true" left-icon="back" :status-bar="true" :border="false" title="收货地址" class="NavBar" @clickLeft="NavBar()">
		</uni-nav-bar>
	
		<view v-if="true" class="editAddress">			
			<view class="topLine"></view>
			 
			<view class="editCommon">
				<text style="width: 136upx; display: inline-block;text-align: right;" class="fl">*姓名：</text><input placeholder="请输入姓名" v-model="editAddress.name" maxlength="15" class="uni-input fl commonInput" />				
			</view>
					
			<view class="editCommon">
				<text style="width: 136upx; display: inline-block;text-align: right;" class="fl">*手机号码：</text><input placeholder="请输入手机号码" v-model="editAddress.mobile" maxlength="11" type="number" class="uni-input fl commonInput" />
			</view>
			
			
			<view @tap="openAddres" class="editCommon">
				<text style="width: 136upx; display: inline-block;text-align: right;" class="fl">*所在地区：</text><input disabled="disabled" v-model="address" type="text" class="uni-input fl commonInput" />				
			</view>
			
			<view class="editCommon">				
				 <text style="width: 136upx; display: inline-block;text-align: right;" class="fl">*详细地址：</text><input placeholder="请输入详细地址" v-model="editAddress.address_xx"  class="uni-input fl commonInput" />
			</view>

	        <button @click="ok()" class="addAddress" type="">确认</button>
		</view>
			
		<simple-address ref="simpleAddress" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onConfirm" themeColor="#007AFF"></simple-address>
	</view>
	
	
</template>

<script>
	import simpleAddress from '@/components/simple-address/simple-address.nvue';
	import provinceData from '@/components/simple-address/city-data/province2.js';
	import cityData from '@/components/simple-address/city-data/city2.js';
	import areaData from '@/components/simple-address/city-data/area2.js';
	export default {
		components: {
			simpleAddress
		},
		data() {
			return {
				lid:"",
				addressId:'',
				member_id:"",
				member_name:"",
				//三级联动
				cityPickerValueDefault: [0, 0, 1],
				pickerText: '',
				
				//add数据
				add_provinceCode:"",
				add_cityCode:"",
				add_areaCode:"",
				
				key:"",
				editIndex:0,
				from:0,//0新增，1修改
				from2:"",
				editFlag:false,
				address:"",
				editAddress:{
					"id":999,
					"name":"",
					"tel":"",
					"mobile":"",			
					"address_sheng":" ",
					"address_shi":" ",
					"address_qu":" ",
					"address_xx":"",
					"isCheck":"false"
				},
				isdefault:false,
				addressLis:[],
				cart_id:"",
				ifcart:"",
				is_global:"",
				order_type:"",
				SpellGroup_sn:"",
				state:""
			}
			
		},
		
		onLoad(options) {		
			this.lid=options.lid
			this.getInfo();
		},
		

		methods: {
			getInfo(){//获取地址信息
				
				this.$util.request({
					url: '/mobile/index.php?act=bigwheel&op=sendinfo',
					method: 'get',
					data: {					
						"lid":this.lid	
					},
				}).then((res)=> {
					if(res.error_code==0){
						
						this.editAddress.name=res.datas.log.send_info.split(' ')[0]
						this.editAddress.mobile=res.datas.log.send_info.split(' ')[1]
						this.address=res.datas.log.send_info.split(' ')[2]
						this.editAddress.address_xx=res.datas.log.send_info.split(' ')[3]
					}else{
						uni.showToast({
							title:res.message,
							icon:"none",
						})
					}
				})		
			},
			
			////三级联动
			openAddres() {
				this.$refs.simpleAddress.open();
			},
			onConfirm(e) {
				this.pickerText = JSON.stringify(e);			
				this.editAddress.address_sheng=e.labelArr[0];
				this.editAddress.address_shi=e.labelArr[1];
				this.editAddress.address_qu=e.labelArr[2];
				this.address=e.label;				
				this.add_provinceCode=JSON.parse(this.pickerText).provinceCode;
				this.add_cityCode=JSON.parse(this.pickerText).cityCode;
				this.add_areaCode=JSON.parse(this.pickerText).areaCode;				
			},
			
			
			 
			
		 
			
			ok(){
				var that=this;
				 
					if(that.editAddress.name.trim().length == 0){
						  uni.showToast({
						  	title:"收货人信息不能为空",
							icon:"none"
						  }) 
						  return false; 
					} 
					if(that.add_areaCode.trim().length == 0){
						  uni.showToast({
						  	title:"收货人地址不能为空",
							icon:"none"
						  }) 
						  return false; 
					} 
					if(that.editAddress.mobile.trim().length == 0){
						  uni.showToast({
						  	title:"收货人手机号不能为空",
							icon:"none"
						  }) 
						  return false; 
					} 
					if(!(/^1[3456789]\d{9}$/.test(that.editAddress.mobile))){
						  uni.showToast({
						  	title:"手机号码有误，请重填",
							icon:"none"
						  }) 
						  return false; 
					} 
					 
					if(that.editAddress.address_sheng.trim().length == 0){
						  uni.showToast({
							title:"请选择地址",
							icon:"none"
						  }) 
						  return false; 
					}
					 
					if(that.editAddress.address_xx.trim().length == 0){
						  uni.showToast({
						  	title:"收货人详细地址不能为空",
							icon:"none"
						  }) 
						  return false; 
					} 	
					let address22 = that.address +" "+ that.editAddress.address_xx
					this.$util.request({
						url: '/mobile/index.php?act=bigwheel&op=sendinfo_save',
						method: 'post',
						data: {					
							"lid":that.lid,
							"username":that.editAddress.name,
							"mobile":that.editAddress.mobile,
							"address":address22							
						},
					}).then((res)=> {
						console.log(res)
						 uni.showToast({
						 	title:res.message,
							icon:"none",
							duration:3000
						 })
						 setTimeout(()=>{							 
							 uni.navigateBack({
								delta:1
							 })
						 },3000)
						 					
					})						
				
				
			},
			NavBar(){
				uni.showModal({
					title: '提示',
					content: '您没有保存是否返回上一页',
					success: function(res2) {
						if (res2.confirm) {
							uni.navigateBack({})
						} else if (res2.cancel) {
							
						}
					}
				})
			}
			
			
		}
	}
</script>

<style>
	.isCheck image{
	
		width: 54upx;
		height: 54upx;
		position: relative;
		top: 20upx;
		margin-right: 10upx;
		margin-left: 30rpx;
	}
	.popup-btn{
		margin-top: 10px;
	}
	.commonInput{
		width: 500upx;
		position: relative;
		top: 8upx;
		height: 50upx;
		border: 1px solid #red;
	}
	.editCommon{
		padding-left: 40upx;
		font-size: 24upx;
		color: #333;
		height: 90upx;
		line-height: 90upx;
		border-bottom: 2upx solid #f5f5f5;
	}
	.fl{
		float: left;
	}
	.fr{
		float: right;
	}
	.fs24C333{
		font-size: 24upx;
		color: #333;
	}
	uni-page-body {
		background-color: #FFFFFF;
		color: rgb(102, 102, 102);
	}
	.topLine{
		width: 710upx;
		height: 110upx;
		margin: 0 auto;
		/* #ifdef APP-PLUS */
			height: 180upx;
		/* #endif */
		/* #ifdef MP-WEIXIN */
			height: 150rpx;
		/* #endif */
		/* background-color: #f5f5f5; */
	}
	.addressLi{
		background-color: #FFFFFF;
		width: 710upx;
		margin: 0 auto;
		border-bottom: 2upx solid #e5e5e5;
		padding:38upx 38upx 88upx 38upx;
		
	}
	.line5{
		width:670upx;
	}
	.line5 image{
		width: 54upx;
		height: 54upx;
		position: relative;
		top: 20upx;
		margin-right: 10upx;
	}
	.addAddress{
		background-color: #ff4300;
		color: #FFFFFF;
		font-size: 30upx;
		width: 100%;
		border-radius: 0;
		position: fixed;
		left: 0;
		bottom: 0;
		line-height: 3.5;
	}
	.editAddress{
		position: fixed;
		z-index: 1;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		width: 100%;
		height: 100%;
		background-color: #fff;
		color: #333333;
		padding:0 20upx;
	}
	.line11{
		color: #333333;
		font-size: 30upx;
		font-weight: bold;
	}
	
	
	
	
	
	.fs30{
		/* font-size: 30upx */
		font-size: 45upx
	}
	.fs26{
		font-size:39upx
		/* font-size: 26upx */
	}
	.fs12{
		font-size: 18upx
		/* font-size: 12upx */
	}
	.fs16{
		font-size: 24upx
		/* font-size: 16upx */
	}
	.fs14{
		font-size: 21upx
		/* font-size: 14upx */
	}
	.fs15{
		font-size: 22.5upx
		/* font-size: 15upx */
	}
	.fs27{
		font-size: 40.5upx
		/* font-size: 27upx */
	}
	.fs18{
		font-size: 27upx
		/* font-size: 18upx */
	}
	.fs28{
		font-size: 42upx
		/* font-size: 28upx */
	}
	.fs10{
		font-size: 15upx
		/* font-size: 10upx */
	}
	.fs30{
		font-size: 45upx
		/* font-size: 28upx */
	}
	.fs24{
		font-size: 36upx
		/* font-size: 24upx */
	}
	.fs20{
		font-size:30upx
		/* font-size: 20upx */
	}
	.fs22{
		font-size:33upx
		/* font-size: 22upx */
	}
	.fs21{
		font-size: 31.5upx
		/* font-size: 21upx */
	}
	.twoline{
	   overflow : hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
</style>
